package com.sc.iconfont;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by SunnyCoffee on 2016/4/27.
 */
public class IconFontAdapter extends RecyclerView.Adapter<IconFontAdapter.MyViewHolder> {


    private Context context;
    private int code = Integer.valueOf("e85a", 16);

    public IconFontAdapter(Context context) {
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_view, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String value = Integer.toHexString(code + position);
        char c = (char) Integer.parseInt(value,16);
        holder.tv.setText(c+"");
        String color = colors[position % colors.length];
        holder.tv.setTextColor(Color.parseColor(color));
    }

    @Override
    public int getItemCount() {
        return 50;
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv);
        }
    }

    static String[] colors = {"#673ab7", "#3f51b5", "#0096bb", "#e51c23", "#ff5722", "#cddc39", "#259b24", "#9c27b0", "#03a9f4"};

}
